package dao;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.PatientDoctor;

import java.util.List;

public interface PatientDoctorMapper {

    // 查询全部，通过 @Results 和 @Result 显式映射字段与属性
    @Select("SELECT * FROM patient_doctor")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "patient_id", property = "patientId"),
            @Result(column = "name", property = "name"),
            @Result(column = "doc_id", property = "docId"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "day", property = "day"),
            @Result(column = "depart_id2", property = "departId2"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "info", property = "info")
    })
    List<PatientDoctor> findAll();

    // 插入操作
    @Insert("INSERT INTO patient_doctor(patient_id, name, doc_id, telephone, day, depart_id2, create_time, info) " +
            "VALUES(#{patientId}, #{name}, #{docId}, #{telephone}, #{day}, #{departId2}, #{createTime}, #{info})")
    int addPatientDoctor(PatientDoctor patientDoctor);

    // 更新操作
    @Update("UPDATE patient_doctor SET patient_id=#{patientId}, name=#{name}, doc_id=#{docId}, telephone=#{telephone}, " +
            "day=#{day}, depart_id2=#{departId2}, create_time=#{createTime}, info=#{info} WHERE id=#{id}")
    int updatePatientDoctor(PatientDoctor patientDoctor);

    // 删除操作
    @Delete("DELETE FROM patient_doctor WHERE id=#{id}")
    int deletePatientDoctor(Integer id);

    // 根据 ID 查询，复用上面定义的 @Results 映射规则（MyBatis 会自动查找同接口中匹配的 @Results ）
    @Select("SELECT * FROM patient_doctor WHERE id=#{id}")
    PatientDoctor findById(Integer id);

    // 根据医生ID查询患者-医生关联数据
    @Select("SELECT * FROM patient_doctor WHERE doc_id=#{docId}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "patient_id", property = "patientId"),
            @Result(column = "name", property = "name"),
            @Result(column = "doc_id", property = "docId"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "day", property = "day"),
            @Result(column = "depart_id2", property = "departId2"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "info", property = "info")
    })
    List<PatientDoctor> findByDocId(String docId);
}